<?php

use app\models\Mall;
use app\models\MallFrontEnd;
use yii\helpers\Url;

$web = Url::base();
$integral_unit = \app\models\Mall::getCurrentInstitutionIntegralUnit();
$site_name = \app\models\Mall::getCurrentInstitutionSiteName();
$institution_code = Mall::getCurrentInstitutionCode();
$this->title = $site_name;
//
$extendCategoryList = MallFrontEnd::getGoodsExtendCategoryList_bs($institution_code);
///场景
$scene_count=4;
$scene = [];
$extendCategoryList_tmp = [];
$scene_i=1;
$scene=array_pad($scene,$scene_count+1,['type'=>'','id'=>'','name'=>'','image_url'=>'']);

foreach ($extendCategoryList as $item) {
    $identifier_code = $item['identifier_code'];
    $is_find=false;
    for($i=1;$i<=$scene_count;$i++){
        if ($identifier_code == 'pc-' . $i) {
            $scene[$i] = $item;
            $is_find=true;
            break;
        }
    }
    if($is_find==false){
        $extendCategoryList_tmp[] = $item;
    }

}
//var_dump($scene);exit;
//var_dump($extendCategoryList_tmp);exit;
$extendCategoryList = $extendCategoryList_tmp;
?>

<link href="<?= $web ?>/css/mall/index.css" rel="stylesheet" type="text/css">

<div class="middle">
    <div class="middle-left">
        <?php
        foreach ($categoryList as $item) {
        ?>
            <div class="nav-list">
                <p class="nav-list-name"><?= $item['name'] ?></p>
                <div class="category hide">
        <?php
            foreach ($item['categoryLv2'] as $item2) {
        ?>
                <div class="category-list">
                    <p class="category-list-name"><?= $item2['name'] ?> ></p>
                    <ul class="tree-view">
        <?php
                foreach ($item2['categoryLv3'] as $item3) {
                    $linkUrl = Url::to(['mall/goods-list', 'goodsCategoryCode' => $item3['code'], 'goodsListTitle' => '商品分类:' . $item3['name'], 'institution_code' => $institution_code]);
                    if ($item['name'] == '时尚卡券') {
                        $linkUrl = Url::to(['mall/virtual-coupon-list', 'tagName' => $item3['name'], 'institution_code' => $institution_code]);
                    }
        ?>
                    <li><a href="<?= $linkUrl ?>"><?= $item3['name'] ?></a></li>
        <?php
                }
        ?>
                    </ul>
                </div>
        <?php
            }
        ?>

                </div>
            </div>
        <?php
        }
        ?>
       <!-- <div class="nav-list">
            <p class="nav-list-name">精品家电</p>
            <div class="category hide">
                <div class="category-list">
                    <p class="category-list-name">汽车周边 ></p>
                    <ul class="tree-view">
                        <li><a href="">精品家电</a></li>
                        <li><a href="">精品家电</a></li>
                        <li><a href="">精品家电</a></li>
                        <li><a href="">精品家电</a></li>
                        <li><a href="">精品家电</a></li>
                        <li><a href="">精品家电</a></li>


                    </ul>
                </div>
                <div class="category-list">
                    <p class="category-list-name">汽车周边 ></p>
                    <ul class="tree-view">
                        <li><a href="">精品家电</a></li>
                        <li><a href="">精品家电</a></li>
                        <li><a href="">精品家电</a></li>
                        <li><a href="">精品家电</a></li>
                        <li><a href="">精品家电</a></li>


                    </ul>
                </div>
            </div>
        </div>-->



    </div>
    <script type="text/javascript">
        $(function(){
            $(".nav-list").mouseover(function(){
                $(this).addClass("curtent-bg");
                $(this).find(".category").removeClass("hide");
                $(this).find(".nav-list-name").addClass("curtent-color");
            });
            $(".nav-list").mouseout(function(){
                $(this).removeClass("curtent-bg");
                $(this).find(".category").addClass("hide");
                $(this).find(".nav-list-name").removeClass("curtent-color");
            });
            var navSize=$(".nav-list").length;
            var navHeight = (387 / navSize);
            var navNameHeight = (navHeight-1);
            $(".middle-left .nav-list").css("height",navHeight+"px");
            $(".middle-left .nav-list .nav-list-name").css({"height":navNameHeight+"px","line-height":navHeight+"px"});
        });
    </script>

    <div class="middle-banner">
        <div class="swiper-container">
            <div class="swiper-wrapper">
                <?php
                foreach ($extendCategoryList as $item) {
                    $link_url = $item['link_url'];
//                  type为2 link_url要换成产品扩展分类列表链接
                    if ($item['type'] == '2') {
                        $link_url = Url::to(['mall/goods-list','cv'=>1, 'goodsExtendCategoryCode' => $item['id'], 'goodsListTitle' => '' . $item['name'], 'institution_code' => $institution_code]);
                    }
                    ?>
                    <div class="swiper-slide">
                        <a href="<?= $link_url ?>">
                            <img src="<?= $item['image_url'] ?>">
                        </a>
                    </div>
                    <?php
                }
                ?>

               <!-- <div class="swiper-slide">
                    <a href=""><img src="imgs/banner1.png" /></a>

                </div>-->

            </div>
            <div class="swiper-button-prev"></div>
            <div class="swiper-button-next"></div>
            <script type="text/javascript">
                $(function(){
                    $(".middle-banner").mouseover(function(){
                        $(".swiper-button-prev,.swiper-button-next").show();
                    });
                    $(".middle-banner").mouseout(function(){
                        $(".swiper-button-prev,.swiper-button-next").hide();
                    });
                    lazy_goods_img();
                });
            </script>
            <div class="swiper-pagination swiper-pagination-clickable swiper-pagination-bullets"></div>
        </div>
        <script language="javascript">
            var mySwiper = new Swiper('.swiper-container', {
                initialSlide: 0,
                speed: 300,
                autoplay: 5000,
                loop: true,
                paginationClickable: true,
                pagination: '.swiper-pagination',
                prevButton:'.swiper-button-prev',
                nextButton:'.swiper-button-next',
                autoplayDisableOnInteraction : false,
                paginationBulletRender: function(index, className) {
                    return '<span class="' + className + '"></span>';
                }
            })
            function lazy_goods_img(){
                //图片延时加载
                $(".hot img,.integral-list img").lazyload({
                    effect: "fadeIn",
                    skip_invisible:false,
                    placeholder:"<?= $web ?>/images/mall-m/goods-list-loading.jpg"
                });

            }
        </script>
    </div>
    <div class="middle-right">
        <p class="modules-name">Hi，欢迎来到<?=$site_name?>！</p>
        <div class="modules">
            <?php $scene_tmp=$scene[1];?>
            <a class="module-lucky-draw" href="<?= $scene_tmp['type'] == '1' ? $scene_tmp['link_url'] : Url::to(['mall/goods-list', 'cv' => 1, 'goodsExtendCategoryCode' => $scene_tmp['id'], 'goodsListTitle' => '' . $scene_tmp['name'], 'institution_code' => $institution_code]) ?>">
                <img  src="<?= $scene_tmp['image_url'] ?>">
            </a>
            <?php $scene_tmp=$scene[2];?>
            <a class="module-delicate-household" href="<?= $scene_tmp['type'] == '1' ? $scene_tmp['link_url'] : Url::to(['mall/goods-list', 'cv' => 1, 'goodsExtendCategoryCode' => $scene_tmp['id'], 'goodsListTitle' => '' . $scene_tmp['name'], 'institution_code' => $institution_code]) ?>">
                <img  src="<?= $scene_tmp['image_url'] ?>">
            </a>
            <?php $scene_tmp=$scene[3];?>
            <a class="module-mother-baby" href="<?= $scene_tmp['type'] == '1' ? $scene_tmp['link_url'] : Url::to(['mall/goods-list', 'cv' => 1, 'goodsExtendCategoryCode' => $scene_tmp['id'], 'goodsListTitle' => '' . $scene_tmp['name'], 'institution_code' => $institution_code]) ?>">
                <img  src="<?= $scene_tmp['image_url'] ?>">
            </a>
            <?php $scene_tmp=$scene[4];?>
            <a class="module-birthday" href="<?= $scene_tmp['type'] == '1' ? $scene_tmp['link_url'] : Url::to(['mall/goods-list', 'cv' => 1, 'goodsExtendCategoryCode' => $scene_tmp['id'], 'goodsListTitle' => '' . $scene_tmp['name'], 'institution_code' => $institution_code]) ?>">
                <img  src="<?= $scene_tmp['image_url'] ?>">
            </a>
        </div>
    </div>
</div>
<!--特价专区-->
<?php
//如果没有特价产品，隐藏
if (count($activityBargainList) > 0) {
?>
    <div class="integral">
    <div class="integral-top">
        <div class="integral-tittle">
            <div class="integral-tittle-img"><img src="<?= $web ?>/images/mall/home-price.jpg"></div>
            <div class="integral-tittle-words">特价专区</div>
        </div>
        <div class="integral-more">
            <div><img src="<?= $web ?>/images/mall/home-2.png"></div>
            <a href="<?=Url::to(['mall/goods-list','isActivity'=>1,'goodsListTitle'=>'特价专区','t'=>time(), 'institution_code' => $institution_code]) ?>">
                <div>更多产品展示</div>
            </a>
        </div>
    </div>
    <div class="integral-list">
        <div class="swiper-container swiper-2">
            <div class="swiper-wrapper  ">
            <?php
            foreach ($bargainGoodsList as $item) {
                ?>
                <div class="swiper-slide list-side">
                    <a href="<?=Url::to(['mall/goods-detail','goods_code'=> $item['goods_code'],  'institution_code' => $institution_code]) ?>" class="list">
                        <img data-original="<?= $item['image_url'] ? $item['image_url'].'@150w': $web.'/images/mall-m/goods-list-nothing.jpg'?>" />
                        <p>
                            <?php
                            if($item['is_crossborder']=='1'){
                                ?>
                                <span class="cross-title-icon">跨境</span>
                                <?php
                            }
                            ?>
                            <?= $item['goods_name'] ?>
                        </p>
                        <p class="old-dhph"><?= intval($item['old_integral']) ?> <?=$integral_unit?></p>
                        <p class="dhph"><?= intval($item['selling_integral']) ?> <?=$integral_unit?></p>
                    </a>
                </div>

                <?php
            }
            ?>
           <!-- <div class="swiper-slide list-side">
							<a href="" class="list">
								<img src="imgs/exchange-img.png" />
								<p>变装小黄人系列之香蕉变装小黄人系列之香蕉</p>
								<p class="old-dhph">199 积分</p>
								<p class="dhph">1 积分</p>
							</a>
						</div>
						-->
        </div>
        </div>
        <script type="text/javascript">
            var swiper2 = new Swiper('.swiper-2', {
                loop: true,
                autoplay: 3000,
                spaceBetween : 20,
                autoplayDisableOnInteraction : false,
                slidesPerView : 6,
//				simulateTouch : false
            });
        </script>
    </div>


</div>
<?php }?>
<div class="clfl"></div>

<div class="hot">
    <div class="hot-title">
        <p><img src="<?= $web ?>/images/mall/hot.png" /> </p>
        <p>热门筛选</p>
    </div>
    <div class="clfl"></div>
    <ul>
        <?php
        foreach ($hotGoodsList as $item) {
            ?>
            <li>
                <a href=" <?=Url::to(['mall/goods-detail','goods_code'=> $item['code'],  'institution_code' => $institution_code]) ?>">
                    <img data-original="<?= $item['image_url'] ? $item['image_url'].'@300w': $web.'/images/mall-m/goods-list-nothing.jpg'?>" />
                    <p>
                        <?php
                        if($item['is_crossborder']=='1'){
                            ?>
                            <span class="cross-title-icon">跨境</span>
                            <?php
                        }
                        ?>
                        <?= $item['name'] ?></p>
                    <p class="rmjf "><span class="now-pace"><?= intval($item['selling_integral']) ?></span>&nbsp;&nbsp;<?= $item['integral_unit'] ?></p>
                </a>
            </li>
            <?php
        }
        ?>
        <!--<li>
            <a href="">
                <img src="imgs/goods.jpg" />
                <p>大牌时尚羊皮双肩包大牌时尚羊皮双肩包大牌时尚羊皮双肩包大牌时尚羊皮双肩包</p>
                <p class="rmjf"><span>199</span>&nbsp;&nbsp;积分</p>
            </a>
        </li>-->


    </ul>

</div>
<?php
    if(count($cardGoodsList)>0){
?>
        <!-------兑换弹窗--------->
        <link rel="stylesheet" type="text/css" href="<?=$web?>/css/mall/convert-window.css" />
        <div class="convert-btn">
            <img src="<?=$web?>/images/mall/convert-btn-img.png" />
        </div>
        <div class="convert-window" style="display: <?=$is_card_show ?'block' : 'none'?>;">
            <div class="conver-content">
                <div class="conver-top">
                    <div class="close-convert-btn">
                        <img src="<?=$web?>/images/mall/close-convert-btn-img.png" />
                    </div>
                </div>
                <div class="center">
                    <div class="center-left">
                        <div class="title">
                            <img src="<?=$web?>/images/mall/convert-card-img.jpg" />
                        </div>
                        <?php
                            $frist_goods=array_shift($cardGoodsList);
                        ?>
                        <div class="center-left-goods">
                            <a href=" <?=Url::to(['mall/goods-detail','goods_code'=> $frist_goods['code'],  'institution_code' => $institution_code]) ?>">
                                <img src="<?= $frist_goods['image'] ?>@300w" />
                                <p>
                                    <?= $frist_goods['name'] ?>
                                </p>
                            </a>
                        </div>
                    </div>
                    <div class="center-right">
                        <ul>
                            <?php
                                $i=1;
                                foreach($cardGoodsList as $item){
                                    $i++;
                                    //右面只能显示6个
                                    if($i>7){
                                        break;
                                    }
                            ?>
                                    <li>
                                        <a href=" <?=Url::to(['mall/goods-detail','goods_code'=> $item['code'],  'institution_code' => $institution_code]) ?>">
                                            <img src="<?= $item['image'] ?>@200w" />
                                            <p><?= $item['name'] ?></p>
                                        </a>
                                    </li>
                            <?php
                                }
                            ?>
                            <!--<li>
                                <a href="">
                                    <img src="imgs/goods.jpg" />
                                    <p>呆萌抱抱大肚呆萌抱抱大肚圣诞陶瓷杯大肚圣诞陶瓷杯大肚</p>
                                </a>
                            </li>-->


                        </ul>
                    </div>
                </div>
                <div class="conver-foot">
                    <a href="goods-list?integralFrom=0&integralTo=<?=Mall::getCurrentUser()['integral']?>" class="more-btn">
                        <img src="<?=$web?>/images/mall/convert-more-btn.png" />
                    </a>
                </div>
            </div>
            <div class="convert-window-shade"></div>

        </div>
        <script type="text/javascript">
            $(function(){
                $(".convert-btn").click(function(){
                    $(".convert-window").show();
                });
                $(".more-btn,.close-convert-btn").click(function(){

                    $(".convert-window").hide();
                })
            });
        </script>

        <!------------------------>
<?php
    }
?>
